﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Xeml.Document
{
    public class ProviderDataMappings : Dictionary<string, DataMappings>
    {


        public new void Add(string key, DataMappings dm)
        {
            base.Add(key, dm);
            dm.CollectionChanged += new EventHandler(dm_CollectionChanged);
            OnCollectionChanged();
            
        }

        void dm_CollectionChanged(object sender, EventArgs e)
        {
            OnCollectionChanged();
        }


        public new bool Remove(string key)
        {
            if(base.ContainsKey(key))
                base[key].CollectionChanged -= new EventHandler(dm_CollectionChanged);
            bool ret = base.Remove(key);
            OnCollectionChanged();
            return ret;
        }

        public new void  Clear()
        {
            foreach (var item in base.Values)
            {
               item.CollectionChanged -= new EventHandler(dm_CollectionChanged);
            }
            base.Clear();
            OnCollectionChanged();
           
        }
        
        public event EventHandler CollectionChanged;
        protected virtual void OnCollectionChanged()
        {
            if (CollectionChanged != null)
                CollectionChanged(this, new EventArgs());
        }
    }
}
